using BlazorApp派单;
using BlazorApp派单.auth;
using BlazorApp派单.Components;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor;
using MudBlazor.Services;
using SqlSugar;
using System.Data;
using DbType = SqlSugar.DbType;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents();

builder.Services.AddBootstrapBlazor();
//builder.Services.AddSingleton<BootstrapBlazor.Components.ConsoleLogger>();
builder.Services.AddControllers();

builder.Services.AddScoped(it => new SqlSugarScope(
         new ConnectionConfig()
         {
             ConnectionString = builder.Configuration.GetConnectionString("actived"),
             DbType = DbType.SqlServer,
             IsAutoCloseConnection = true
         }
           ,
           db =>
           {
               db.Aop.OnLogExecuting = (sql, pars) =>
               {
               };
               }
           ));
//builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
//builder.Services.AddScoped<ICustomAuthenticationService,CustomAuthenticationService>();

//// 注册自定义的 AuthenticationStateProvider
//builder.Services.AddTransient<AuthenticationStateProvider, CustomAuthenticationStateProvider>();

//// 同时注册 CustomAuthenticationStateProvider 作为自身
//builder.Services.AddTransient<CustomAuthenticationStateProvider>();

// 注册自定义的认证服务
//builder.Services.AddTransient<ICustomAuthenticationService, CustomAuthenticationService>();


builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
builder.Services.AddMvc();
builder.Services.AddHttpContextAccessor();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
}

app.UseStaticFiles();

app.UseRouting();
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
app.UseAuthentication();
app.MapControllers();
app.UseAntiforgery();


app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode();

app.Run();
